<template>
  <div>
    <div>
      <el-form ref="formInline" :inline="true" :model="formInline" :rules="formInlineRules" class="demo-form-inline">
        <el-form-item label="机构">
          <el-select v-model="formInline.mechanism" placeholder="请选择">
            <el-option label="全部" value=""></el-option>
            <el-option label="机构一" value="shanghai"></el-option>
            <el-option label="机构二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查询类别">
          <el-select v-model="formInline.category" placeholder="请选择">
            <el-option label="按年查询" value="year"></el-option>
            <el-option label="按月查询" value="month"></el-option>
            <el-option label="按日查询" value="day"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="日期" prop="timeYear" v-if="formInline.category == 'year'">
          <el-date-picker
            v-model="formInline.timeYear"
            type="year"
            placeholder="选择年"
            value-format="yyyy"
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="日期" prop="timeMonth" v-if="formInline.category == 'month'">
          <el-date-picker
            v-model="formInline.timeMonth"
            type="month"
            placeholder="选择月"
            value-format="yyyy-MM"
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="日期" prop="timeDay" v-if="formInline.category == 'day'">
          <el-date-picker
            v-model="formInline.timeDay"
            align="right"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"
                     v-if="formInline.category == 'year'"
                     icon="el-icon-search"
                     @click="handleSetLineChartData('newVisitis', formInline.timeYear)">查询
          </el-button>
          <el-button type="primary"
                     v-if="formInline.category == 'month'"
                     icon="el-icon-search"
                     @click="handleSetLineChartData('messages', formInline.timeMonth)">查询
          </el-button>
          <el-button type="primary"
                     v-if="formInline.category == 'day'"
                     icon="el-icon-search"
                     @click="handleSetLineChartData('messages', formInline.timeDay)">查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              HIS收费
            </div>
            <count-to :start-val="0" :end-val="102400" :duration="2600" class="card-panel-num" />
            元/
            <count-to :start-val="0" :end-val="5" :duration="3000" class="card-panel-num" />
            笔
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="jine" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              实际收费
            </div>
            <count-to :start-val="0" :end-val="81212" :duration="3000" class="card-panel-num" />
            元/
            <count-to :start-val="0" :end-val="5" :duration="3000" class="card-panel-num" />
            笔
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              长款
            </div>
            <count-to :start-val="0" :end-val="9280" :duration="3200" class="card-panel-num" />
            元/
            <count-to :start-val="0" :end-val="5" :duration="3000" class="card-panel-num" />
            笔
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-changkuan">
            <svg-icon icon-class="changkuan" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              短款
            </div>
            <count-to :start-val="0" :end-val="13600" :duration="3600" class="card-panel-num" />
            元/
            <count-to :start-val="0" :end-val="5" :duration="3000" class="card-panel-num" />
            笔
          </div>
        </div>
      </el-col>
      <el-col  :xs="12" :sm="12" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shouyin" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              平账
            </div>
            <count-to :start-val="0" :end-val="13600" :duration="3600" class="card-panel-num" />
            元/
            <count-to :start-val="0" :end-val="5" :duration="3000" class="card-panel-num" />
            笔
          </div>
        </div>
      </el-col>
    </el-row>
    <!--<el-row>
      <el-col :xs="24" :sm="24" :lg="16">
        <div>
          <span>异常交易趋势</span>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div>
          <span>异常交易占比</span>
        </div>
      </el-col>
    </el-row>-->
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import { formatDate } from '@/filters/index'

export default {
  components: {
    CountTo
  },
  data() {
    return {
      formInline: {
        mechanism: '',
        category: 'year',
        timeYear: formatDate(new Date(), 'yyyy'),
        timeMonth: formatDate(new Date(), 'yyyy-MM'),
        timeDay: formatDate(new Date(), 'yyyy-MM-dd ')
      },
      formInlineRules: {
        timeYear: [{ required: true, message: '日期不能为空', trigger: 'blur' }],
        timeMonth: [{ required: true, message: '日期不能为空', trigger: 'blur' }],
        timeDay: [{ required: true, message: '日期不能为空', trigger: 'blur' }]
      },
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
      },
    }
  },
  methods: {
    getNowTime() {
      var now = new Date()
      var year = now.getFullYear()
      var month = now.getMonth()
      var date = now.getDate()
      month = month + 1
      month = month.toString().padStart(2, '0')
      date = date.toString().padStart(2, '0')
      var defaultDate = `${year}-${month}-${date}`
      console.log(defaultDate)
      return defaultDate
      this.$set(this.formInline, 'stockDate', defaultDate)
    },
    handleSetLineChartData(type, time) {
      this.$refs.formInline.validate(valid => {
        if (valid) {
          this.$emit('handleSetLineChartData', type, time)
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
      .icon-changkuan {
        background: #FBCE77
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }
    .icon-changkuan {
      color: #FBCE77
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
